<?
function writeDateTime($name, $date){
	echo '<select name="'.$name.'" class=inpts>';
	foreach ( $date  as $data ) {
		echo '<option value="';
		echo $data ['VALUE'].'"';
		echo ($data ['SELECTED'] == 1 ? 'selected' : '');
		echo' >';
			echo $data ['NAME'];
		echo '</option>';
	}
  echo '</select>';
}


$frm ['gid'] = intval ( $frm ['gid'] );
$frm ['lid'] = intval ( $frm ['lid'] );
$q = 'select * from hl_listings where id = ' . $frm ['lid'];
if (! ($sth = mysql_query ( $q ))) {
	exit ( mysql_error () );
}

$row = mysql_fetch_array ( $sth );
if (! $row) {
	print 'Invalid listing id';
	exit ();
}

$q = 'select * from hl_groups';
if (! ($gsth = mysql_query ( $q ))) {
	exit ( mysql_error () );
}

$listings = array ();
while ( $grow = mysql_fetch_array ( $gsth ) ) {
	array_push ( $listings, $grow );
}
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="a" value="edit_listing">
<input type="hidden" name="action" value="save">
<input type="hidden" name="lid" value="<?php echo $frm ['lid'];?>" >
<input type="hidden" name="gid" value="<?php echo $frm ['gid']?>">
<input type="hidden" name="p" value="<?php echo $frm ['p'];?>">
<input type="hidden" name="return" value="<?php echo $frm ['return'];?>">
<table cellspacing=1 cellpadding=2 border=0 width=100%>
	<tr>
	 <td width=30%>Name:</td>
	 <td><input type="text" name="name" value="<?php echo htmlspecialchars ( $row ['name'] );?> " class=inpts size=50> </td>
	</tr>
	<tr>
		<td>Group:</td><td>
			<select name="group_id" class=inpts>
			<?php foreach ( $listings as $group ) {?> 
				<option value="<?php echo $group ['id'];?>" <?php echo ($group ['id'] == $row ['group_id'] ? 'selected' : '');?> >
				<?php echo htmlspecialchars ( $group ['name'] );?>
				</option>
			<?php }?>
		</select>
		</td>
	</tr>
<tr>
 <td>Rating:</td>
 <td>
	<select name="rating" class=inpts>
		<?php for($i = 0; $i <= 5; ++ $i) {?>
			<option value='<?php echo $i;?>' <?php echo ($i == $row ['rating'] ? 'selected' : '');?>>
			<?php echo $i;?>
			</option>
		<?php }?>
	</select>
 </td>
</tr>
<tr>
 <td>Status:</td>
 <td>
 	<select name="status" class=inpts>
     <option value=0 <?php echo ($row ['status'] == 0 ? 'selected' : '');?>>Off</option>
     <option value=1 <?php echo ($row ['status'] == 1 ? 'selected' : '');?>>On</option>
     <option value=2 <?php echo ($row ['status'] == 2 ? 'selected' : '');?>>Not Approved</option>
  </select>
  </td>
</tr>
<tr>
 <td>Paying Status:</td>
 <td>
 	<select name="hyip_status" class=inpts>
     <option value=1 <?php echo ($row ['hyip_status'] == 1 ? 'selected' : '');?> >Paying</option>
     <option value=2 <?php echo ($row ['hyip_status'] == 2 ? 'selected' : '');?> >Waiting</option>
     <option value=3 <?php echo ($row ['hyip_status'] == 3 ? 'selected' : '');?> >Problem</option>
     <option value=4 <?php echo ($row ['hyip_status'] == 4 ? 'selected' : '');?> >Not Paying</option>
   </select>
  </td>
</tr>
<tr>
 	<td>
 		URL:</td>
 	<td>
 		<input type="text" name="url" value="<?php echo htmlspecialchars ( $row ['url'] );?>" class=inpts size=50>
	</td>
</tr>
<tr>
 <td>Percents:</td>
 <td>
 	<input type="text" name="percents" value="<?php echo htmlspecialchars ( $row ['percents'] );?>" class=inpts size=50>
 </td>
</tr>
<tr>
 <td>Minimal Spend:</td>
 <td>
 	<input type="text" name="min_spend" value="<?php echo htmlspecialchars ( $row ['min_spend'] );?>" class=inpts size=50>
 </td>
</tr>
<tr>
 <td>Maximal Spend:</td>
 <td>
 	<input type="text" name="max_spend" value="<?php echo htmlspecialchars ( $row ['max_spend'] );?>" class=inpts size=50>
 </td>
</tr>
<tr>
 <td>Referral:</td>
 <td>
 	<input type="text" name="referral" value="<?php echo htmlspecialchars ( $row ['referral'] );?>" class=inpts size=50>
 </td>
</tr>
<tr>
 <td>Withdrawal:</td>
 <td>
 		<select name="withdrawal_type" class=inpts>
     <option value=1 <?php echo ($row ['withdrawal_type'] == 1 ? 'selected' : '');?> >Manual</option>
     <option value=2 <?php echo ($row ['withdrawal_type'] == 2 ? 'selected' : '');?> >Instant</option>
     <option value=3 <?php echo ($row ['withdrawal_type'] == 3 ? 'selected' : '');?> >Automatic</option>
   </select>
 </td>
</tr>
<tr>
	<td>Contact E-mail:</td>
  <td>
  	<input type="text" name="email" value="<?php echo htmlspecialchars ( $row ['email'] );?>" class=inpts size=50>
	</td>
</tr>
<tr>
	<td>Support E-mail:</td>
  <td>
  	<input type="text" name="support_email" value="<?php echo htmlspecialchars ( $row ['support_email'] );?>" class=inpts size=50>
	</td>
</tr>

<tr>
 <td>Support Forum (MMG):</td>
 <td>
 	<input type="text" name="support_forum" value="<?php echo htmlspecialchars ( $row ['support_forum'] );?>" class=inpts size=50>
 </td>
</tr>
<tr>
 <td>Support Forum (TG):</td>
 <td><input type="text" name="support_form" value="<?php echo htmlspecialchars ( $row ['support_form'] );?>" class=inpts size=50>
 </td>
</tr>
<tr>
<td>Support Forum (DTM):</td>
<td>
	<input type="text" name="support_aim" value="<?php echo htmlspecialchars ( $row ['support_aim'] );?>" class=inpts size=50>
</td>
</tr>

<tr>
<tr>
 <td>Added:</td>
<?php 
preg_match ( '/(\\d+)-(\\d+)-(\\d+)/', $row ['date_added'], $parts );
$date = get_date_arrays ( $parts [1], $parts [2], $parts [3], 10, 10);
?> 
 <td>
 	<?php writeDateTime('month', $date ['MONTHS']);?>
 	<?php writeDateTime('day', $date ['DAYS']);?>
 	<?php writeDateTime('year', $date ['YEARS']);?>
 </td>
</tr>


<tr>
 <td>Started:</td>
<?php 
preg_match ( '/(\\d+)-(\\d+)-(\\d+)/', $row ['date_started'], $parts );
$date = get_date_arrays ( $parts [1], $parts [2], $parts [3], 10, 10 );
?> 
 <td>
 	<?php writeDateTime('smonth', $date ['MONTHS']);?>
 	<?php writeDateTime('sday', $date ['DAYS']);?>
 	<?php writeDateTime('syear', $date ['YEARS']);?>
 </td>
</tr>


<tr>
 <td>Expires after:</td>
 <td>
 		<input type="text" name="expiration" value="<?php echo htmlspecialchars ( $row ['expiration'] );?>" class=inpts size=50>
		days (enter \'0\' to skip limitation)
 </td>
</tr>
<tr>
 <td>Closed:</td>
<?php preg_match ( '/(\\d+)-(\\d+)-(\\d+)/', $row ['date_closed'], $parts );
if (($parts [1] != 0 and $parts [1] - date ( 'Y' ) < - 5)) {
	$prev_years = date ( 'Y' ) - $parts [1] + 5;
} else {
	$prev_years = 5;
}

$date = get_date_arrays ( $parts [1], $parts [2], $parts [3], $prev_years, 5 );
?>
	<td>
		<select name="cmonth" class=inpts>
   		<option value=0>-</option>
			<?php foreach ( $date ['MONTHS'] as $data ) {?>
				<option value="<?php echo $data ['VALUE'];?>" <?php echo ($data ['SELECTED'] == 1 ? 'selected' : '');?>>
					<?php echo $data ['NAME'];?>
				</option>
			<?php }?>
  	</select>
		<select name="cday" class=inpts>
	   	<option value=0>-</option>
	   	<?php foreach ( $date ['DAYS'] as $data ) {?>
				<option value="<?php echo $data ['VALUE'];?>" <?php echo ($data ['SELECTED'] == 1 ? 'selected' : '');?>>
					<?php echo $data ['NAME'];?>
				</option>
			<?php }?>
  </select>
	<select name="cyear" class=inpts>
   <option value=0>-</option>
   <?php foreach ( $date ['YEARS'] as $data ) {?>
			<option value="<?php echo $data ['VALUE'];?>" <?php echo ($data ['SELECTED'] == 1 ? 'selected' : '');?>>
				<?php echo $data ['NAME'];?>
			</option>
		<?php }?>
  </select>
 </td>
</tr>
<tr>
  <td valign=top>Payment Systems:</td>
  <td>
		<?php $payments = preg_split ( '/\\s*,\\s*/', $settings ['payments'] );
		$apayments = preg_split ( '/\\s*,\\s*/', $row ['pay_systems'] );
		foreach ( $payments as $payment ) {?>
			<input type="checkbox" name="payments[<?php echo $payment;?>]" value=1 <?php echo (in_array ( $payment, $apayments ) ? 'checked' : '');?> />
			<?php echo $payment;?>
			<br>
		<?php }?>
	</td>
</tr>
<?php $a_accounts = preg_split ( '/\\|/', $row ['account'] );
$b_accounts = array ();
for($i = 0; $i < sizeof ( $a_accounts ); ++ $i) {
	if ($a_accounts [$i] == '') {
		continue;
	}
	
	array_push ( $b_accounts, $a_accounts [$i] );
}

$accounts = join ( ',', $b_accounts );
?>
<tr>
 <td>HYIP E-currency Accounts<br>
 		<small>comma sparated</small>:</td>
 		<td><input type="text" name="account" value="<?php echo htmlspecialchars ( $accounts );?>" class=inpts size=10>
 		</td>
</tr>
<tr>
<td>Review:</td>
<td>
	<textarea name="support_phone" cols=82 rows=5 class=inpts>
		<?php echo $row ['description'];?>
	</textarea>
</td>
</tr>
<tr>
  <td colspan=2>Description:</td>
</tr>
<tr>
  <td colspan=2>
  	<textarea name="description" cols=82 rows=5 class=inpts>
			<?php echo $row ['description'];?>
		</textarea>
	</td>
</tr>
<tr>
  <td>Monitoring Image: </td>
<?php 
if (is_file ( './image.php' )) {
	$sn = $frm_env ['SCRIPT_NAME'];
	$sn = preg_replace ( '/admin\\.php/', 'image.php', $sn );
	$sn .= '?lid=' . $row ['id'];
} else {
	$sn = $frm_env ['SCRIPT_NAME'];
	$sn = preg_replace ( '/admin\\.php/', 'index.php', $sn );
	$sn .= '?a=image&lid=' . $row ['id'];
}
?>
<td>
	<a href="http://<?php echo $frm_env ['HTTP_HOST'] . $sn;?> " target=_blank>http://<?php echo $frm_env ['HTTP_HOST'] . $sn;?> </a>
</td>
</tr>
<tr>
  <td colspan=2><input type="submit" value="Update" class=sbmt></td>
</tr>
</table>
</form>
